package com.th.supcom.pds.config.server;

import java.util.List;

import net.carefx.framework.container.client.exception.UiException;
import net.carefx.framework.util.ConvertUtils;
import net.carefx.framework.web.gwt.server.GwtController;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.th.supcom.pds.config.client.model.PhamDispensaryConfigModel;
import com.th.supcom.pds.config.client.service.PhamDispensaryConfigRpc;
import com.th.supcom.pds.domain.pojo.PhamDispensaryConfig;
import com.th.supcom.pds.internal.api.config.PhamDispensaryConfigService;

/**
 * PhamDispensaryConfig 控制层.
 * 
 * 药房属性.
 */
public class PhamDispensaryConfigServiceController extends GwtController implements PhamDispensaryConfigRpc
{
    /** 公司版权信息. */
    public static final String copyright = "Copyright 2014, TH Supcom Corporation";
    /** 日志记录器. */
    public static final Logger s_logger = LoggerFactory.getLogger (PhamDispensaryConfigServiceController.class);

    /** 提交路径. */
    public static final String SCC_BRANCH = "$URL$";

    /** 提交日期. */
    public static final String SCC_LAST_MODIFICATION_DATE = "$Date$";

    /** 最终修改人员. */
    public static final String SCC_LAST_MODIFIER_NAME = "$Author$";

    /** 最终版本号. */
    public static final String SCC_REVISION = "$Revision$";

    private static final long serialVersionUID = 1L;

    private PhamDispensaryConfigService m_phamDispensaryConfigService;

    @Override
    public void addPhamDispensaryConfig (final PhamDispensaryConfigModel phamDispensaryConfigModel) throws UiException
    {
        PhamDispensaryConfigServiceController.s_logger.debug ("call addPhamDispensaryConfig (PhamDispensaryConfigModel phamDispensaryConfigModel=【{}】)", phamDispensaryConfigModel);
        final PhamDispensaryConfig phamDispensaryConfig = ConvertUtils.convert (PhamDispensaryConfig.class, phamDispensaryConfigModel);
        try
        {
            m_phamDispensaryConfigService.addPhamDispensaryConfig (phamDispensaryConfig);
        }
        catch (final Exception e)
        {
            PhamDispensaryConfigServiceController.s_logger.error (e.getMessage (), e);
            throw new UiException (e.getMessage (), e);
        }
    }

    @Override
    public List <PhamDispensaryConfigModel> findPhamDispensaryConfigByExample (final PhamDispensaryConfigModel model) throws UiException
    {
        PhamDispensaryConfigServiceController.s_logger.debug ("call findPhamDispensaryConfigByExample (PhamDispensaryConfigModel phamDispensaryConfigModel=【{}】)", model);
        final PhamDispensaryConfig phamDispensaryConfig = ConvertUtils.convert (PhamDispensaryConfig.class, model);
        try
        {
            final List <PhamDispensaryConfig> list = m_phamDispensaryConfigService.findPhamDispensaryConfigByExample (phamDispensaryConfig);
            final List <PhamDispensaryConfigModel> modelList = ConvertUtils.convert (PhamDispensaryConfigModel.class, list);
            return modelList;
        }
        catch (final Exception e)
        {
            PhamDispensaryConfigServiceController.s_logger.error (e.getMessage (), e);
            throw new UiException (e.getMessage (), e);
        }
    }

    @Override
    public PhamDispensaryConfigModel getPhamDispensaryConfigById (final Long id) throws UiException
    {
        PhamDispensaryConfigServiceController.s_logger.debug ("call getPhamDispensaryConfigById (Long id=【{}】)", id);
        try
        {
            final PhamDispensaryConfig phamDispensaryConfig = m_phamDispensaryConfigService.getPhamDispensaryConfigById (id);
            final PhamDispensaryConfigModel model = ConvertUtils.convert (PhamDispensaryConfigModel.class, phamDispensaryConfig);
            return model;
        }
        catch (final Exception e)
        {
            PhamDispensaryConfigServiceController.s_logger.error (e.getMessage (), e);
            throw new UiException (e.getMessage (), e);
        }
    }

    @Override
    public void modifyPhamDispensaryConfig (final PhamDispensaryConfigModel phamDispensaryConfigModel) throws UiException
    {
        PhamDispensaryConfigServiceController.s_logger.debug ("call modifyPhamDispensaryConfig (PhamDispensaryConfigModel phamDispensaryConfigModel=【{}】)",
                                                              phamDispensaryConfigModel);
        final PhamDispensaryConfig phamDispensaryConfig = ConvertUtils.convert (PhamDispensaryConfig.class, phamDispensaryConfigModel);
        try
        {
            m_phamDispensaryConfigService.modifyPhamDispensaryConfig (phamDispensaryConfig);
        }
        catch (final Exception e)
        {
            PhamDispensaryConfigServiceController.s_logger.error (e.getMessage (), e);
            throw new UiException (e.getMessage (), e);
        }
    }

    @Override
    public void modifyPhamDispensaryConfigByExample (final PhamDispensaryConfigModel phamDispensaryConfigModel) throws UiException
    {
        PhamDispensaryConfigServiceController.s_logger.debug ("call modifyPhamDispensaryConfigByExample (PhamDispensaryConfigModel phamDispensaryConfigModel=【{}】)",
                                                              phamDispensaryConfigModel);
        final PhamDispensaryConfig phamDispensaryConfig = ConvertUtils.convert (PhamDispensaryConfig.class, phamDispensaryConfigModel);
        try
        {
            m_phamDispensaryConfigService.modifyPhamDispensaryConfigByExample (phamDispensaryConfig);
        }
        catch (final Exception e)
        {
            PhamDispensaryConfigServiceController.s_logger.error (e.getMessage (), e);
            throw new UiException (e.getMessage (), e);
        }
    }

    @Override
    public void removePhamDispensaryConfig (final Long id) throws UiException
    {
        PhamDispensaryConfigServiceController.s_logger.debug ("call getPhamDispensaryConfigById (Long id=【{}】)", id);
        final PhamDispensaryConfig phamDispensaryConfig = new PhamDispensaryConfig ();
        phamDispensaryConfig.setPhamDispensaryConfigId (id);
        try
        {
            m_phamDispensaryConfigService.removePhamDispensaryConfig (phamDispensaryConfig);
        }
        catch (final Exception e)
        {
            PhamDispensaryConfigServiceController.s_logger.error (e.getMessage (), e);
            throw new UiException (e.getMessage (), e);
        }
    }

    public void setPhamDispensaryConfigService (final PhamDispensaryConfigService phamDispensaryConfigService)
    {
        m_phamDispensaryConfigService = phamDispensaryConfigService;
    }
}